import axios from 'axios'
import { ElMessage } from 'element-plus'

const isNewVersion = () => {
  let url = `//${window.location.host}/version.json?t=${new Date().getTime()}`
  axios.get(url).then(res => {
    if (res.status === 200) {
      let vueVersion = res.data.version || '1.0.0'
      let localVueVersion = localStorage.getItem('vueVersion')
      localStorage.setItem('vueVersion', vueVersion)
      if (localVueVersion && localVueVersion !== vueVersion) {
        ElMessage.warning('检测到新版本，刷新页面')
        window.location.reload()
      }
    }
  })
}

export default {
  isNewVersion
}